package cn.z2huo.knowledge.basic.random;

import cn.hutool.core.util.RandomUtil;
import org.apache.commons.lang3.RandomUtils;

import java.util.Random;

/**
 * <p>生成随机 long 值
 *
 * @author z2huo
 */
public class RandomLongDemo {

    public static void mathRandomLong() {
        long randomLong = (long) (Math.random() * (Long.MAX_VALUE - Long.MIN_VALUE + 1)) + Long.MIN_VALUE;
        System.out.println("Random long value: " + randomLong);
    }

    public static void randomLong() {
        Random random = new Random();
        long l = random.nextLong();
        System.out.println("Random long value: " + l);
    }

    public static void hutoolRandomLong() {
        long l = RandomUtil.randomLong();
        System.out.println("Random long value: " + l);
    }

    public static void apacheRandomLong(){
        long l = RandomUtils.nextLong(Long.MIN_VALUE, Long.MAX_VALUE);
        System.out.println("Random long value: " + l);
    }

    public static void main(String[] args) {
        hutoolRandomLong();
        apacheRandomLong();
    }

}
